home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6399 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.8 KB

  1. Path: fourier.newcastle.edu.au!peter
  2. From: peter@fourier.newcastle.edu.au (Peter Moylan)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2
  4. Subject: Re: Hungarian notation
  5. Followup-To: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2
  6. Date: 7 Feb 1996 22:35:27 GMT
  7. Organization: The University of Newcastle
  8. Message-ID: <4fb9ff$s2t@seagoon.newcastle.edu.au>
  9. References: <30C40F77.53B5@swsbbs.com> <Pine.HPP.3.91.960124153551.24374C-100000@zeezrom.cs.byu.edu> <4e7ifl$et3@goanna.cs.rmit.EDU.AU> <Pine.HPP.3.91.960129133429.8419C-100000@foggy.cs.byu.edu> <4em29qINN39r@keats.ugrad.cs.ubc.ca> <Pine.HPP.3.91.960201015336.17360C-100000@clear.cs.byu.edu> <4f41vf$g8j@goanna.cs.rmit.EDU.AU>
  10. Reply-To: peter@tesla.newcastle.edu.au
  11. NNTP-Posting-Host: fourier.newcastle.edu.au
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14. Richard A. O'Keefe (ok@goanna.cs.rmit.EDU.AU) wrote:
  15. >Douglas Evan Cook <cookd@cs.byu.edu> writes:
  16. >>Good grief :)  You just declare one type as another.  In Pascal or M2, try
  17. >>TYPE
  18. >>  INT16 : INTEGER;
  19.  
  20. >This is not legal Pascal syntax.  Is it legal Modula 2?
  21.  
  22. There was a minor typo here.  If you replace the ':' by '=' then
  23. it's legal Modula-2.
  24.  
  25. >The original poster's point remains:  the
  26. >    <type name> = <type term>;
  27. >construction in Pascal does not create abstract data types and does not
  28. >"unify" anything, let alone "thousands of ADTs".
  29.  
  30. Perhaps not, but there are two separate issues here.  If all
  31. you want to do is mimic the C typedef facility, then the above
  32. is a way to do it.  If instead you want to implement an
  33. abstract data type, you certainly can do that in Modula-2
  34. but it would be silly to do it simply by mimicking the
  35. C approach - that would amount to throwing away some of the
  36. benefits of Modula-2.  In fact you wouldn't often find a
  37. type definition like the above in typical Modula-2 modules.
  38. Likewise for other high-level languages like Ada, Modula-3, etc.
  39.  
  40. There seems to be a general misunderstanding in this thread
  41. about the motivations for using the abstraction and information
  42. hiding facilities of languages like Modula-2.  The point is
  43. not primarily to hide things from the programmer, since
  44. typically the programmer has the option of going and looking
  45. at the source code anyway.  Rather, the point is to enhance
  46. portability, code reliability, and ease of programming, by
  47. letting the programmer concentrate on his own area of
  48. responsibility, and being able to use facilities provided by
  49. other modules, without having to keep checking for
  50. unintended side-effects that are dependent on how those
  51. other modules are implemented.
  52.  
  53. If you want an abstract data type, then you create a module
  54. that defines that type (usually without revealing the details
  55. of its internal representation) and defines the operations
  56. that can be performed on the type.  If subsequently you need
  57. to use a different internal representation (e.g. you change
  58. data structures for efficiency reasons, or you're doing
  59. something machine-dependent and you port the code to another
  60. machine), then all you have to do is update the internal
  61. implementation of the ADT and - this is the important point -
  62. YOU DON'T BREAK ANY OF THE CLIENT CODE.
  63.  
  64. In the specific case of implementation details that depend
  65. on the underlying representation (e.g. reading data produced
  66. by a machine with a different architecture), the representation
  67. details are all collected in one place and program porting
  68. becomes very easy.
  69.  
  70. There seems to be a very common tendency among C/C++
  71. programmers to use typedefs to introduce low-level types
  72. like int16.  Modula-2 programmers use type definitions for
  73. exactly the opposite reason: to introduce high-level types
  74. in such a way that the user doesn't have to worry about
  75. what the underlying representation looks like.
  76.  
  77. --
  78. Peter Moylan                       peter@ee.newcastle.edu.au
  79.                            ftp://ee.newcastle.edu.au/pub/www/Moylan.html
  80.